<template>
    <v-chart class="chart" :option="option"></v-chart>
</template>

<script>
import axios from 'axios'

export default ({
    name: 'Chart',
    props: ['id'],
    data: function () {
    return {
        option: {
            title: {
                text: "历史发文记录",
                left: "center"
            },
            tooltip: {
                trigger: "item",
                formatter: "{c}"
            },
            xAxis: {
                type: 'time',  
                name: '年份',   // x轴名称
                // // x轴名称样式
                // nameTextStyle: {
                //     fontWeight: 600,
                //     fontSize: 15
                // }
            },
            yAxis: {
                type: 'value',
                name: '发文数量',   // y轴名称
                // // y轴名称样式
                // nameTextStyle: {
                //     fontWeight: 600,
                //     fontSize: 15
                // }
            },
            series: [
                {
                    name: '所有信息',
                    type: "line",
                    smooth: true,
                    symbol: "circle",
                    data: [],
                },
            ]
        }
    }
  },
  created() {
        this.getList2()
    },
  methods: {
    getList2() {
        axios.get('/api/countByYear/author', {
            params: {author: this.$props.id}
        }).then(res => {
            if (res.data.success) {
                console.log(res.data)
                for(var index in res.data.data) {
                    var tmparr = new Array();
                    tmparr[0] = index
                    tmparr[1] = res.data.data[index]
                    console.log(tmparr)
                    this.option.series[0].data.push(tmparr)
                }
            } else {
                this.$message.error(res.data.info)
            }
        })
    },      
  }
})
</script>

<style scoped>
.chart {
  height: 200px;
}
</style>